This invention relates to the field of computer graphics. More particularly, a method and apparatus are provided to facilitate the drawing or manipulation of a document using a virtual view tree of the document.
The drawing of a document, and corresponding communication between a graphics application that manipulates the document (i.e., a program for creating, modifying or displaying computer graphics) and a graphics library for displaying the document (i.e., a library of program code for rendering graphics), is traditionally handled in any of multiple ways.
In an immediate mode of operation, a set of graphics APIs (Application Programming Interfaces) is offered by the graphics library for drawing primitives that, together, compose a drawing or document. A drawing may comprise any type of displayable content, and so the primitives rendered by the APIs may include graphical shapes, images, text, data, and/or other types of objects or drawing attributes. When an application needs to display a particular drawing, it invokes the library's APIs as needed to render the individual details (e.g., to draw a line, draw a character). In the immediate mode of operation, the application maintains its own data structures for identifying the content and primitives. GDI (Graphical Device Interface) and Java2D employ the immediate mode of operation.
In this mode of operation, use of the graphics library is driven by the application. The library cannot optimize the rendering process, because it does not control data structures containing the drawing content. Rendering speeds could be improved in many cases if the graphics library knew ahead of time that a drawing did or did not employ some characteristic (e.g., transparency, color palette). Whenever a portion of the drawing changes, the application must specifically and individually instruct the library to re-render every detail of the drawing that needs to be redrawn.
In a retained mode of operation, a data structure called a view tree is defined and maintained by a graphics library. A view tree is a hierarchical data structure representing a document, and may comprise any number of nodes. Leaf nodes store content of the document, while a root node and intermediate nodes describe document structure containing the content. For example, a root node may represent an entire document or a page of a document. Intermediate nodes may group individual letters into words, glyphs into graphical objects, words into paragraphs, etc.
In the retained mode of operation, a view tree is specific to a particular graphics library, is fully defined, can be completely traversed by that library and is stored in a persistent manner. An application accesses and modifies the library's view tree, directly or through some interface, and the library renders it as necessary. SVG (Scalable Vector Graphics), HTML (HyperText Markup Language) browsers can work in retained mode.
In this mode of operation, there can be a great deal of data duplication between the library's view tree and the actual low-level data being rendered, which may deplete resources (e.g., memory) and slow the rendering. In addition, the application loses control over the data structures used by the library to drive the rendering. Because the graphics library works with primitive details of a drawing, the view tree that describes the entire drawing may be very large. It must retain all the details, and therefore may require significant storage (e.g., memory) resources.
Thus, in an immediate mode of computer graphics operation, an application invokes APIs within a library to draw individual atomic elements. Memory requirements may be low because the elements are re-generated every time they are needed. Performance, however, may suffer if there is a lot of regeneration of drawing content. In contrast, in a retained mode of operation an entire drawing is maintained by a graphics library as a view tree. The library can re-render the drawing whenever needed, but memory requirements can be significant. And, the application has no access to the data structures describing the drawing.